package com.dzt.androidframework.jsoup.news;

import com.dzt.androidframework.jsoup.news.bean.ImageNews;
import com.dzt.androidframework.jsoup.news.model.NewsDataSource;
import com.dzt.androidframework.jsoup.news.model.RemoteNewsDataSource;
import com.dzt.androidframework.utils.JLogKit;

import java.util.List;

/**
 * Created by M02323 on 2017/7/12.
 */

public class ImageNewsPresenter implements ImageNewContract.Presenter {

	private ImageNewContract.View imageNewsView;
	private RemoteNewsDataSource dataSource;

	public ImageNewsPresenter(RemoteNewsDataSource dataSource, ImageNewContract.View view) {
		this.dataSource = dataSource;
		imageNewsView = view;
	}

	@Override
	public void start() {

	}

	@Override
	public void getImageList(int page) {
		if (page == 1) {
			imageNewsView.showLoading();
		}
		dataSource.getImageNewList(page, new NewsDataSource.OnImageNewLoadListener() {

			@Override
			public void onSuccess(List<ImageNews.DataEntity> imageNews) {
				JLogKit.getInstance().i("onSuccess");
				imageNewsView.hideLoading();
				imageNewsView.addImage(imageNews);
			}

			@Override
			public void onFailed(String msg, Exception e) {
				JLogKit.getInstance().i("onFailed");
				imageNewsView.hideLoading();
				imageNewsView.showLoadFailed();
			}
		});
	}
}
